/* 
 * File:   Contexte.h
 * Author: Gab'z
 *
 * Created on 30 avril 2012, 14:02
 */

#ifndef CONTEXTE_H
#define	CONTEXTE_H
#include "ElementContexte.h"
#include "Parametres.h"
#include "Pile.h"
#include "model\UserCommand.h"

namespace calculatrice {

    namespace MODEL {

        class Contexte {
        private:
            static Contexte * context;
            Contexte();
            Contexte(const Contexte& orig);
            virtual ~Contexte();

            Parametres parametres;
            std::map<std::string, UserCommand> userCommands;
            std::list<Pile> piles;

            ContexteKeeper* lGardien;

            void setParametres(const Parametres& p) {
                parametres = p;
            }

            void setUserCommands(const UserCommand* uc, unsigned int n) {
                userCommands.erase(userCommands.begin(), userCommands.end());
                for (unsigned int i = 0; i < n; i++) {
                    userCommands[uc[i].getName()] = userCommands[uc[i].clone()];
                }
            }

            void setPiles(const Pile* p, unsigned int n) {
                piles.erase(piles.begin(), piles.end());
                for (unsigned int i = 0; i < n; i++) {
                    piles.push_back(p[i].clone());
                }
            }

            void newPile();
            void setCurrentPile(unsigned int i);
            void deletePile(unsigned int i);


        public:

            Parametres& getParametres() const {
                return parametres;
            }

            std::list<Pile>& getPiles() const {
                return piles;
            }

            std::map<std::string, UserCommand>& getUserCommands() const {
                return userCommands;
            }

            Memento* createMemento() {
                return new Memento(this);
            }

            void setMemento(const Memento* m) {
                setParametres(m->parametres);
                setUserCommands(m->userCommands, m->nb_userCommands);
                setPiles(m->piles, m->nb_piles);
            }
        };



    }
}
#endif	/* CONTEXTE_H */

